
#include "iostream"
#include "vector"
#include "unordered_map"
#include "unordered_set"
#include "algorithm"
#include "string"
#include "list"
#include "string.h"

class OneLoop {
public:
    bool run(
    ) {
        bool ret= true;
        int line_cnt=0;

        std::vector<std::string> vec1;
        std::vector<std::string> vec2;

        std::string buf;
        while (1){
            char c=std::cin.get();
            if(c==EOF||c=='\n'){
                if(c==EOF){
                    ret=false;
                }
                if(line_cnt==0){
                    vec1.push_back(buf);
                }else{
                    vec2.push_back(buf);
                }
                line_cnt++;
                if(line_cnt==2){
                    break;
                }
            }
            else if(c==' '){
                if(line_cnt==0){
                    vec1.push_back(buf);
                }else{
                    vec2.push_back(buf);
                }
                buf.clear();
            }else{
                buf+=c;
            }
        }
        struct MatchStr{
            struct C_Counter{
                int arr[26]={0};
                void count(std::string& s){
                    for(auto c:s){
                        arr[c-'a']++;
                    }
                }
                bool same(C_Counter& cc){
                    for(int i=0;i<26;i++){
                        if(arr[i]!=cc.arr[i]){
                            return false;
                        }
                    }
                    return true;
                }
            };
            std::unordered_map<std::string,C_Counter> map;
            auto match(std::string &s1,std::string&s2)->bool {
                if(s1.size()!=s2.size()){
                    return false;
                }
                if(map.find(s1)==map.end()){
                    map[s1]=C_Counter();
                    map[s1].count(s1);
                }
                if(map.find(s2)==map.end()){
                    map[s2]=C_Counter();
                    map[s2].count(s2);
                }
                return map[s1].same(map[s2]);
            }
        };
        MatchStr m;
        bool first= true;
        for(auto &model:vec1){
            bool match=false;
            for(auto &s:vec2){
                if(m.match(model,s)){
                    match= true;
                    break;
                }
            }

            if(match){
                if(!first){
                    printf(" ");
                }
                first=false;
                std::cout<<model;
            }
        }
        printf("\n");
        return ret;
    }
};

class Solution {
public:
    void run() {

        bool first = true;
        int a, b, c, d, e;
        while(1){
            OneLoop l;
            if(!l.run()){
                return;
            }
        }


    }
};

int main() {
//    bool cur_num= true;
    Solution().run();
    return 0;
}

